/********************************************************************************
* File Name:	mainform.cpp
* Description:	第十一章实例训练
* Reference book:《Linux环境下Qt4图形界面与MySQL编程》，机械工业出版社.2012.1
* E_mail: openlinux2011@gmail.com
********************************************************************************/
#include "mainform.h"
#include "ui_foodorder.h"

#include "dlgfoodmanger.h"
#include "dlgorder.h"
#include "dlgsearch.h"
#include "dlgcount.h"
#include <QAbstractItemView>


MainForm::MainForm(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainForm)
{
    ui->setupUi(this);

    this->model=new QSqlTableModel(this);
    this->model->setTable("food");
    ui->tvMainList->setModel(model);
    //格式化表
    this->model->removeColumn(this->model->fieldIndex("fid"));
    this->model->removeColumn(this->model->fieldIndex("flag"));
    this->model->setHeaderData(0,Qt::Horizontal,tr("名称"));
    this->model->setHeaderData(1,Qt::Horizontal,tr("类型"));
    this->model->setHeaderData(2,Qt::Horizontal,tr("价格"));
    this->model->setHeaderData(3,Qt::Horizontal,tr("热度"));

    //按热度值获取表中数据 并按降序排列
    this->model->setFilter("fhot_count>10 order by fhot_count desc");
    this->model->select();

    //设置 tableview 不可编辑
    ui->tvMainList->setEditTriggers(QAbstractItemView::NoEditTriggers);
}

MainForm::~MainForm()
{
    delete ui;
}

void MainForm::on_pbMain_Manager_clicked()
{
    DlgFoodManger *dlg1=new DlgFoodManger(this);
    dlg1->show();
}

void MainForm::on_pbMain_Order_clicked()
{
    DlgOrder *dlg2=new DlgOrder(this);
    dlg2->show();
}

void MainForm::on_pbMain_Search_clicked()
{
    DlgSearch *dlg3=new DlgSearch(this);
    dlg3->show();
}

void MainForm::on_pbMain_Count_clicked()
{
    DlgCount *dlg4=new DlgCount(this);
    dlg4->show();
}

void MainForm::on_pbMain_Exit_clicked()
{
    this->close();
}
